package com.haoxiaozi.www.GUIFunctionStudy;

import java.awt.*;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-12-07
 * Time: 15:08
 */
public class FrameDemo2 {
    public static void main(String[] args) throws InterruptedException {
        Random random = new Random();
        for (int i = 0; i < 50; i++) {
            Thread.sleep(400);
            MyFrame frame = new MyFrame(random.nextInt(1400),random.nextInt(600),250,250,
                    new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255)));
        }
    }
}

//继承Frame类
class MyFrame extends Frame{
    //设置窗口编号
    static int id = 0;

    public MyFrame(int x, int y, int width, int height, Color color){
        //先调用父类构造器完成初始化
        super("MyFrame " + ++id);

        setBackground(color);
        setSize(width,height);
        setLocation(x,y);
        setVisible(true);
        setResizable(false);
    }
}
